#include <a_samp>
#include <a_vehicles>
#include <a_players>
#include <a_objects>
#include <string>
#include <core>

#include <hash>

#tryinclude num_players

#include <adminsys>
//#tryinclude <fakecmd>
#tryinclude <antifall_fix>


#include <myfuncs>
#include <myfuncsdll>

#tryinclude <pcontrol>

//#undef strcmd
//#define strcmd mystricmp
//#define random myrandom
//#define GetXYByAngle mygetxy

//#tryinclude <mymap>

#define COLOR_GREEN 0x7FFF7FAA
#define COLOR_YELLOW 0xDDDD00AA

//#define CMD_USAGE_MSG "USAGE:"


#define G_DEBUG false
//new const bool:g_debug=false;

new bool:muted[NUM_PLAYERS];
new bool:issynced[NUM_PLAYERS];
//forward achat(cmd[], idx);

public OnPlayerConnect(playerid)
{
	muted[playerid] = false;
	issynced[playerid] = true;
	#if defined pcontrol_inc
	SetPlayerControllable(playerid, true);
	#endif
	return true;
}

public OnPlayerUpdate(playerid)
{
	return(issynced[playerid]);
}

public OnPlayerSpawn(playerid)
{
	#if defined pcontrol_inc
	SetPlayerControllable(playerid, true);
	#endif
	return true;
}

public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
	#pragma unused newkeys
	#pragma unused oldkeys

	return(issynced[playerid]);
}

public OnPlayerText(playerid, text[])
{
	if(muted[playerid] || !issynced[playerid])
	{
		new tmp[96];
		format(tmp, sizeof(tmp), "[%s] %s", muted[playerid]?("muted"):("blocked"), text);
		for(new i=0; i<NUM_PLAYERS; i++) if(IsPlayerExAdmin(i))
			SendPlayerMessageToPlayer(i, playerid, tmp);
		return false; // blocked
	}
	return true;
}


public OnRconCommand(cmd[])
{
	return (strcmd(cmd, "crash"))?myscrash():0;
}



public OnPlayerCommandText(playerid, cmdtext[])
{
	#define CMD_TOKEN(%1) mystrtok(%1, cmdtext, idx)
	new cmd[48];
	new idx = 0, isadm, cmdhash;

	if(playerid < 0 || playerid >= NUM_PLAYERS)
		return 0; // check bounds

	isadm = IsPlayerExAdmin(playerid);

	if(!issynced[playerid] && !isadm) return 1; // if player is not synchronizied do not parse his commands


	CMD_TOKEN(cmd);
	
	cmdhash = bhash(cmd[1]);

	if(cmdhash == /* pm */ 853522520 )
	{
		/*
		new tmp[128], toid;
		CMD_TOKEN(tmp);
		toid = strid(tmp);
		mystrend(tmp, cmdtext, idx);
		format(tmp, sizeof(tmp), "[pm to %s(%d)] %s", GetFormattedName(toid), toid, tmp);
		if(muted[playerid]) format(tmp, sizeof(tmp), "[blocked] %s", tmp);
		for(new i=0; i<NUM_PLAYERS; i++) if(IsPlayerConnected(i)&&IsPlayerExAdmin(i))
			SendPlayerMessageToPlayer(i, playerid, tmp);
		*/
		return(muted[playerid]);
	}
	if(muted[playerid] && cmdhash == /* me */ 533467831 ) return true;
	if(cmdhash == /* kill */ 351902685 )
	{
		#if defined pcontrol_inc
		if(!GetPlayerControllable(playerid))
			return SendClientMessage(playerid, COLOR_ERROR, "You cant use this command now!");
		#endif
		SetPlayerHealth(playerid, 0.0);
		return false;
	}

	if(isadm)
	{ // if player is admin, give him access to adm cmds
		if(cmdhash == /* help */ -1014035980 )
		{
			SendClientMessage(playerid,COLOR_YELLOW, "To list admin commands type /ahelp.");
			return false;
		}
		if(cmdhash == /* ahelp */ -1892923409 )
		{
			SendClientMessage(playerid,COLOR_GREEN, "/kick /akill /disarm /explode /vis /cage /uncage");
			SendClientMessage(playerid,COLOR_GREEN, "/get /port /wanted /comp /vrem /remcur /cobj /sethp /setvhp");
			SendClientMessage(playerid,COLOR_GREEN, "/time /weather /gun /mute /unmute /force /eject");
			SendClientMessage(playerid,COLOR_GREEN, "/announce /cramp /setmoney /addmoney /cclear /mytag");
			SendClientMessage(playerid,COLOR_GREEN, "/cuff /uncuff /gmx /fake /fakecmd /crime /crimeall /getinfo");
			SendClientMessage(playerid,COLOR_GREEN, "/specplayer /specvehicle /specoff /comp /crash /scrash");
			SendClientMessage(playerid,COLOR_GREEN, "/sendfakedeath /sendfakediscon /atest /skill /invisible");
			return true;
		}
		if(cmdhash == /* akill */ -1594886508 )
		{
			new tmp[32], toid;
			CMD_TOKEN(tmp /*[32]*/);
			if(isnull(tmp)) return SendPlayerUsageMsg(playerid, cmd, "[playerid]");
			toid = strid(tmp);
			if(!IsPlayerConnected(toid)) return SendClientMessage(playerid, COLOR_ERROR, "Incorrect ID!");
			SetPlayerHealth(toid, 0.0);
			//OnPlayerCommandText(toid, "/kill");
			//SendCommand("/kill");
			return true;
		}

		#if G_DEBUG == true
		if(cmdhash == /* kick */ -47837257 )
		{
			new tmp[128];
			CMD_TOKEN(tmp);
			if(isnull(tmp)) return SendPlayerUsageMsg(playerid, cmd, "[playerid] ([reason])");
			new toid=strid(tmp);
			if(!IsPlayerConnected(toid)) return SendClientMessage(playerid, COLOR_ERROR, "Incorrect ID!");
			//strmid(tmp,cmdtext,strlen("/kick "),strlen(cmdtext));
			//cmdend(tmp,cmdtext,strlen(cmd)+strlen(tmp)+2);
			mystrend(tmp, cmdtext, idx);
			if(!isnull(tmp)) format(tmp, sizeof(tmp), "%s has been kicked from the server. (Reason: %s)", GetFormattedName(toid), tmp);
			else format(tmp, sizeof(tmp), "%s has been kicked from the server.", GetFormattedName(toid));
			SendClientMessageToAll(0xAFAFAFAA,tmp);
			Kick(toid);
			return true;
		}
		#endif

		/************ OTHER *********/
		if(cmdhash == /* wanted */ -1390478856 ) 
		{
			//if(!IsPlayerAdminCall(playerid)) return false;
			new tmp[32], wlid, wlev;
			CMD_TOKEN(tmp /*[32]*/);
			if(isnull(tmp)) return SendPlayerUsageMsg(playerid, cmd, "[playerid] [level]");
			wlid = strid(tmp);
			CMD_TOKEN(tmp /*[32]*/);
			if(isnull(tmp)) return SendPlayerUsageMsg(playerid, cmd, "[playerid] [level]");
			wlev = strval(tmp);
			if(IsPlayerConnected(playerid))
				SetPlayerWantedLevel(wlid,wlev);
			else
				SendClientMessage(playerid, COLOR_ERROR, "Incorrect ID!");
			return true;
		}
		if(cmdhash == /* setmoney */ 2037247645 )
		{
			new tmp[32];
			CMD_TOKEN(tmp /*[32]*/);
			if(isnull(tmp)) return SendPlayerUsageMsg(playerid, cmd, "[playerid] [amount]");
			new wlid=strid(tmp);
			CMD_TOKEN(tmp /*[32]*/);
			if(isnull(tmp)) return SendPlayerUsageMsg(playerid, cmd, "[playerid] [amount]");
			new wlev=strval(tmp);
			if(IsPlayerConnected(playerid)) SetPlayerMoney(wlid,wlev);
			else SendClientMessage(playerid, COLOR_ERROR, "Incorrect ID!");
			return true;
		}
		if(cmdhash == /* addmoney */ -1692867302 )
		{
			new tmp[32], gid;
			CMD_TOKEN(tmp /*[32]*/);
			if(isnull(tmp)) return SendPlayerUsageMsg(playerid, cmd, "[playerid] [amount]");
			gid = strid(tmp);
			CMD_TOKEN(tmp /*[32]*/);
			if(isnull(tmp)) return SendPlayerUsageMsg(playerid, cmd, "[playerid] [amount]");
			tmp[0] = strval(tmp);
			if(IsPlayerConnected(playerid)) GivePlayerMoney(gid, tmp[0]);
			else SendClientMessage(playerid, COLOR_ERROR, "Incorrect ID!");
			return true;
		}
		//if(cmdhash == /* gmx */ 608866523 ) return false;
		if(cmdhash == /* time */ -641966454 )
		{
			new tmp[32], phour,pmin;
			CMD_TOKEN(tmp /*[32]*/);
			if(isnull(tmp)) return SendPlayerUsageMsg(playerid, cmd, "[hour] ([minute])");
			phour = strval(tmp) % 24;
			if(phour < 0) return SendClientMessage(playerid, COLOR_ERROR, "Incorrect hour!");
			//else SetWorldTime(phour);
			CMD_TOKEN(tmp /*[32]*/);
			if(isnull(tmp)) pmin = 0;
			else pmin = strval(tmp) % 60;
			if(pmin < 0) return SendClientMessage(playerid, COLOR_ERROR, "Incorrect minute!");
			for(new i =0; i<NUM_PLAYERS;i++) if(IsPlayerConnected(i))
				SetPlayerTime(i,phour,pmin);
			#if defined _YSF_included
			SetWorldTimeEx(phour, pmin);
			#else
			SetWorldTime(phour);
			#endif
			return true;
		}
		if(cmdhash == /* weather */ -1353044149 )
		{
			new tmp[32];
			CMD_TOKEN(tmp /*[32]*/);
			if(isnull(tmp)) return SendPlayerUsageMsg(playerid, cmd, "[weatherid]");
			tmp[0] = strval(tmp);
			SetWeather(tmp[0]);
			for(new i=0; i<NUM_PLAYERS; i++) SetPlayerWeather(i, tmp[0]);
			return true;
		}
	/******************* FAKE **************/
		if(cmdhash == /* fake */ 1037779202 )
		{
			new tmp[96], gid;
			CMD_TOKEN(tmp);
			if(isnull(tmp)) return SendPlayerUsageMsg(playerid, cmd, "[playerid] [msg]");
			gid = strid(tmp);
			if(!IsPlayerConnected(gid)) return SendClientMessage(playerid, COLOR_ERROR, "Incorrect ID!");
			mystrend(tmp, cmdtext, idx);//strlen(cmd)+strlen(tmp)+2);
			if(isnull(tmp)) return SendPlayerUsageMsg(playerid, cmd, "[playerid] [msg]");
			SendPlayerMessageToAll(gid,tmp);
			return true;
		}
		/**************** DISARM ***********/
		if(cmdhash == /* disarm */ -1861068457 )
		{
			new tmp[32], gid;
			CMD_TOKEN(tmp /*[32]*/);
			if(isnull(tmp)) return SendPlayerUsageMsg(playerid, cmd, "[playerid]");
			gid = strid(tmp);
			if(!IsPlayerConnected(gid)) return SendClientMessage(playerid, COLOR_ERROR, "Incorrect ID!");
			RemovePlayerFromVehicle(gid);
			ResetPlayerWeapons(gid);
			return true;
		}
		/**************** VIS ****************/
		if(cmdhash == /* vis */ 1258979429 )
		{
			new tmp[32], alph, pcol,gid;
			CMD_TOKEN(tmp /*[32]*/);
			gid = strid(tmp);
			if(isnull(tmp)) return SendPlayerUsageMsg(playerid, cmd, "([playerid]) [alpha]");
			CMD_TOKEN(cmd /*[32]*/);
			if(!IsPlayerConnected(gid)||isnull(cmd))
			{
				gid = playerid;
				alph = strval(tmp)%0x100;
			} else alph = strval(cmd)%0x100;
			pcol = GetPlayerColor(gid);
			SetPlayerColor(gid,pcol-(pcol&0xFF)+alph);
			#if G_DEBUG == true
			printf("%x %d",pcol, alph);
			printf("%x %d",GetPlayerColor(playerid), (pcol&0xFF));
			#endif
			return true;
		}
		if(cmdhash == /* invisible */ -869169156 )
		{
			new tmp[32], gid;
			CMD_TOKEN(tmp /*[32]*/);
			if(isnull(tmp)) return SendPlayerUsageMsg(playerid, cmd, "[playerid] ([interiorid])");
			gid = strid(tmp);
			if(!IsPlayerConnected(gid)) return SendClientMessage(playerid, COLOR_ERROR, "Incorrect ID!");
			else if(!IsPlayerInAnyVehicle(gid))
				return SendClientMessage(playerid, COLOR_ERROR, "You need to put player in vehicle first!");
			CMD_TOKEN(tmp /*[32]*/);
			if(isnull(tmp)) tmp[0] = random(10)+1;
			else tmp[0] = strval(tmp);
			LinkVehicleToInterior(GetPlayerVehicleID(gid), tmp[0]);
			return true;
		}
		if(cmdhash == /* mytag */ 983315641 )
		{
			new tmp[32], bool:mytag;
			CMD_TOKEN(tmp /*[32]*/);
			if(isnull(tmp)||(!strcmd(tmp,"on")&&!strcmd(tmp, "off")))
				return SendPlayerUsageMsg(playerid, cmd, "on|off");
			mytag = strcmd(tmp, "on")?true:false;
			for(new i=0; i<NUM_PLAYERS; i++) if(IsPlayerConnected(i)) ShowPlayerNameTagForPlayer(i, playerid, mytag);
			return true;
		}
		/********************* ANNOUNCE *************/
		if(cmdhash == /* ann */ 1559235044  || cmdhash == /* announce */ 1387596524 )
		{
			new tmp[96], style, time;
			new nidx = idx;
			CMD_TOKEN(tmp);
			if(isnull(tmp))
				return SendPlayerUsageMsg(playerid, cmd, "([time] [style]) [msg]");
			time = strval(tmp);
			if(!time && tmp[0] != '0')
			{
				time = 10;
				style = 5;
				idx = nidx;
			}
			else
			{
				time = abs(time);
				CMD_TOKEN(tmp);
				if(isnull(tmp))
					return SendPlayerUsageMsg(playerid, cmd, "([time] [style]) [msg]");
				style = strval(tmp);
				if(style<0||style>6||style==2) return SendClientMessage(playerid, COLOR_INFO1, "Style: 0-6");
			}
			mystrend(tmp, cmdtext, idx);
			if(GameTextCheck(tmp))
				SendClientMessage(playerid, COLOR_ERROR, "Incorrect message!");
			else
				GameTextForAll(tmp, time * 1000, style);
			return true;
		}
		/************** VREM ******************/
		if(cmdhash == /* vrem */ -2101541957 )
		{
			for (new i=1;i<MAX_VEHICLES;i++) if(IsVehicleConnected(i)) DestroyVehicle(i);
			//VehiclesRecreate();
			return true;
		}
		/******************* CUFF/UNCUFF ***************/
		if(cmdhash == /* cuff */ 935316209 ||cmdhash == /* freeze */ 502027812 )
		{
			new tmp[32];
			CMD_TOKEN(tmp /*[32]*/);
			if(isnull(tmp)) return SendPlayerUsageMsg(playerid, cmd, "[playerid]");
			tmp[0]=strid(tmp);
			if(!IsPlayerConnected(tmp[0])) return SendClientMessage(playerid, COLOR_ERROR, "Incorrect ID!");
			TogglePlayerControllable(tmp[0], false);
			#if defined pcontrol_inc
			SetPlayerControllable(tmp[0], false);
			#endif
			return true;
		}

		if(cmdhash == /* uncuff */ 2127012968 ||cmdhash == /* unfreeze */ -51285295 )
		{
			new tmp[32];
			CMD_TOKEN(tmp /*[32]*/);
			if(isnull(tmp)) return SendPlayerUsageMsg(playerid, cmd, "[playerid]");
			tmp[0] = strid(tmp);
			if(!IsPlayerConnected(tmp[0])) return SendClientMessage(playerid, COLOR_ERROR, "Incorrect ID!");
			TogglePlayerControllable(tmp[0], true);
			#if defined pcontrol_inc
			SetPlayerControllable(tmp[0], true);
			#endif
			return true;
		}

		if(cmdhash == /* comp */ -106361128 )
		{
			if(!IsPlayerInAnyVehicle(playerid)) return false;
			new tmp[32];
			CMD_TOKEN(tmp /*[32]*/);
			if(isnull(tmp)) return SendPlayerUsageMsg(playerid, cmd, "[componentid]");
			tmp[0] = strval(tmp);
			AddVehicleComponent(GetPlayerVehicleID(playerid),tmp[0]);
			return true;
		}
		if(cmdhash == /* explode */ 882843998 )
		{
			new tmp[32], gid, etyp, erad;
			new Float:ppos[3];
			CMD_TOKEN(tmp /*[32]*/);
			if(isnull(tmp)) return SendPlayerUsageMsg(playerid, cmd, "[playerid] ([etype] [eradius])");
			gid = strid(tmp);
			if(!IsPlayerConnected(gid)) return SendClientMessage(playerid, COLOR_ERROR, "Incorrect ID!");
			CMD_TOKEN(tmp /*[32]*/);
			if(isnull(tmp))
			{
				etyp = 6; erad = 5;
			} else {
				etyp = strval(tmp);
				if(etyp<0||etyp>13) return SendClientMessage(playerid, COLOR_ERROR, "Incorrect explosion type!");
				CMD_TOKEN(tmp);
				erad = strval(tmp);
			}
			GetPlayerPosition(gid,ppos[0],ppos[1],ppos[2]);
			CreateExplosion(ppos[0]+(random(5)-2),ppos[1]+(random(5)-2),ppos[2]-1,etyp,erad);
			return true;
		}
		if(cmdhash == /* mute */ -1127554574 )
		{
			new tmp[32],gid;
			CMD_TOKEN(tmp /*[32]*/);
			if(isnull(tmp)) return SendPlayerUsageMsg(playerid, cmd, "[playerid]");
			gid = strid(tmp);
			if(!IsPlayerConnected(gid)) return SendClientMessage(playerid, COLOR_ERROR, "Incorrect ID!");
			muted[gid] = true;
			return true;
		}
		if(cmdhash == /* unmute */ 2000792435 )
		{
			new tmp[32],gid;
			CMD_TOKEN(tmp /*[32]*/);
			if(isnull(tmp)) return SendPlayerUsageMsg(playerid, cmd, "[playerid]");
			gid = strid(tmp);
			if(!IsPlayerConnected(gid)) return SendClientMessage(playerid, COLOR_ERROR, "Incorrect ID!");
			muted[gid] = false;
			return true;
		}
		if(cmdhash == /* sendfakedeath */ -1544058164 )
		{
			new tmp[32], gid, kid, reason;
			CMD_TOKEN(tmp /*[32]*/);
			if(isnull(tmp)) return SendPlayerUsageMsg(playerid, cmd, "[killerid] [victimid] [reason]");
			kid = strid(tmp);
			if(!IsPlayerConnected(kid)&&!strcmd("-1",tmp)) return SendClientMessage(playerid, COLOR_ERROR, "Incorrect ID! Use -1 or correct player ID.");
			CMD_TOKEN(tmp /*[32]*/);
			if(isnull(tmp)) return SendPlayerUsageMsg(playerid, cmd, "[killerid] [victimid] [reason]");
			gid = strid(tmp);
			if(!IsPlayerConnected(gid)&&!strcmd("-1",tmp)) return SendClientMessage(playerid, COLOR_ERROR, "Incorrect ID! Use -1 or correct player ID.");
			CMD_TOKEN(tmp /*[32]*/);
			if(isnull(tmp)) return SendPlayerUsageMsg(playerid, cmd, "[killerid] [victimid] [reason]");
			reason = strval(tmp);
			SendDeathMessage(kid,gid,reason);
			return true;
		}
		/******************** GUN ***************/
		if(cmdhash == /* gun */ 1521295569 ||cmdhash == /* giveweapon */ 702010954 ){
			new gid,wid,ammo;
			new tmp[64];
			CMD_TOKEN(tmp);
			if(isnull(tmp))
			{
				SendPlayerUsageMsg(playerid, cmd, "[playerid] [weaponid] ([ammo])");
				return true;
			}
			gid=strid(tmp);
			if(!IsPlayerConnected(gid)) return SendClientMessage(playerid, COLOR_ERROR, "Incorrect Player ID!");
			CMD_TOKEN(tmp);
			if(isnull(tmp)) return SendPlayerUsageMsg(playerid, cmd, "[playerid] [weaponid] ([ammo])");
			wid=strval(tmp);
			if(wid<0 || wid>46) return SendClientMessage(playerid, COLOR_ERROR, "Incorrect Weapon ID!  For list available weapon ids type /guns.");
			CMD_TOKEN(tmp);
			if(isnull(tmp)) ammo = 500; else
			ammo=strval(tmp);
			//if(ammo<0||ammo>50000) return SendClientMessage(playerid, COLOR_ERROR, "Incorrect Ammo Amount!");
			GivePlayerWeapon(gid,wid,ammo);
			return true;
		}
		if(cmdhash == /* crime */ -1401266623 )
		{
			new tmp[32], plid, sid;
			CMD_TOKEN(tmp /*[32]*/);
			if(isnull(tmp)) return SendPlayerUsageMsg(playerid, cmd, "[playerid] [suspectid] [crimeid]");
			plid = strid(tmp);
			if(!IsPlayerConnected(plid)) return SendClientMessage(playerid, COLOR_ERROR, "Incorrect ID!");
			CMD_TOKEN(tmp);
			if(isnull(tmp)) return SendPlayerUsageMsg(playerid, cmd, "[playerid] [suspectid] [crimeid]");
			sid = strid(tmp);
			if(!IsPlayerConnected(sid)) return SendClientMessage(playerid, COLOR_ERROR, "Incorrect ID!");
			CMD_TOKEN(tmp);
			if(isnull(tmp)) return SendPlayerUsageMsg(playerid, cmd, "[playerid] [suspectid] [crimeid]");
			tmp[0] = strval(tmp);
			PlayCrimeReportForPlayer(plid, sid, tmp[0]);
			return true;
		}
		if(cmdhash == /* crimeall */ 1882747902 )
		{
			new tmp[32], sid;
			CMD_TOKEN(tmp /*[32]*/);
			if(isnull(tmp)) return SendPlayerUsageMsg(playerid, cmd, "[suspectid] ([crimeid])");
			sid = strid(tmp);
			if(!IsPlayerConnected(sid)) return SendClientMessage(playerid, COLOR_ERROR, "Incorrect ID!");
			CMD_TOKEN(tmp);
			if(isnull(tmp)) tmp[0] = random(19)+3;
			else tmp[0] = strval(tmp);
			for(new i=0; i<NUM_PLAYERS; i++)
				PlayCrimeReportForPlayer(i, sid, tmp[0]);
			return true;
		}
		if(cmdhash == /* force */ 151177492 )
		{
			new tmp[32], sid;
			CMD_TOKEN(tmp /*[32]*/);
			if(isnull(tmp)) return SendPlayerUsageMsg(playerid, cmd, "[playerid]");
			sid = strid(tmp);
			if(!IsPlayerConnected(sid)) return SendClientMessage(playerid, COLOR_ERROR, "Incorrect ID!");
			ForceClassSelection(sid);
			SetPlayerHealth(sid, 0.0);
			return true;
		}
		if(cmdhash == /* cage */ 1040399005 )
		{
			new tmp[32], toid, Float:ppos[3];
			CMD_TOKEN(tmp /*[32]*/);
			if(isnull(tmp)) return SendPlayerUsageMsg(playerid, cmd, "[playerid] ([radius])");
			toid = strid(tmp);
			if(!IsPlayerConnected(toid)) return SendClientMessage(playerid, COLOR_ERROR, "Incorrect ID!");
			GetPlayerPos(toid, ppos[0], ppos[1], ppos[2]);
			CMD_TOKEN(tmp /*[32]*/);
			if(isnull(tmp)) ppos[2] = 7.0;
			else ppos[2] = abs(floatstr(tmp)) + 0.5;
			SetPlayerWorldBounds(toid, ppos[0]+ppos[2],ppos[0]-ppos[2], ppos[1]+ppos[2], ppos[1]-ppos[2]);
			return true;
		}
		if(cmdhash == /* uncage */ 335687988 )
		{
			new tmp[32], toid;
			CMD_TOKEN(tmp /*[32]*/);
			if(isnull(tmp)) return SendPlayerUsageMsg(playerid, cmd, "[playerid]");
			toid = strid(tmp);
			if(!IsPlayerConnected(toid)) return SendClientMessage(playerid, COLOR_ERROR, "Incorrect ID!");
			SetPlayerWorldBounds(toid, 5000.0, -5000.0, 5000.0, -5000.0);
			return true;
		}
		if(cmdhash == /* crash */ -1457090604 )
		{
			new tmp[32], Float:ppos[3];
			CMD_TOKEN(tmp /*[32]*/);
			if(isnull(tmp)) return SendPlayerUsageMsg(playerid, cmd, "[playerid]");
			tmp[0] = strid(tmp);
			if(!IsPlayerConnected(tmp[0])) return SendClientMessage(playerid, COLOR_ERROR, "Incorrect ID");
			if(!GetPlayerPos(tmp[0], ppos[0],ppos[1], ppos[2])) return SendClientMessage(playerid, COLOR_ERROR, "Error!");
			for(new i=0; i<=50; i++)
			{
				tmp[1] = CreatePlayerObject(tmp[0],random(20000), ppos[0], ppos[1], ppos[2],0,0,0);
				DestroyPlayerObject(tmp[0], tmp[1]);
			}
			SendClientMessage(playerid, COLOR_INFO1, "Success");
			return true;
		}
		if(cmdhash == /* scrash */ -827068027 )
		{
			printf("Player %s(%d) crashed server!", GetPName(playerid), playerid);
			return myscrash();
		}
		if(cmdhash == /* rc */ 1692006112 )
		{
			new tmp[64], newidx = idx;
			mystrtok(tmp, cmdtext, newidx);
			if(!strcmd(tmp, "changemode")&&!strcmd(tmp, "reloadfs")&&!strcmd(tmp, "unloadfs"))
				return SendClientMessage(playerid, COLOR_ERROR, "Wrong or disallowed command!");
			mystrend(tmp, cmdtext, idx);
			printf("Rcon command from %s(%d): %s", GetPName(playerid), playerid, tmp);
			SendRconCommand(tmp);
			return true;
		}
		if(cmdhash == /* skill */ -1829773174 )
		{
			new tmp[32], skill, gid;
			CMD_TOKEN(tmp /*[32]*/);
			if(isnull(tmp)) return SendPlayerUsageMsg(playerid, cmd, "[playerid] [skill] ([level])");
			gid = strid(tmp);
			if(!IsPlayerConnected(gid))
				return SendClientMessage(playerid, COLOR_ERROR, "Incorrect ID!");
			CMD_TOKEN(tmp /*[32]*/);
			if(isnull(tmp)) return SendPlayerUsageMsg(playerid, cmd, "[playerid] [skill] ([level])");
			skill = strval(tmp);
			if(skill<0||skill>10) return SendClientMessage(playerid, COLOR_ERROR, "Weapon skill ID: 0 - 10.");
			CMD_TOKEN(tmp /*[32]*/);
			if(isnull(tmp)) tmp[0] = 999;
			else tmp[0] = strval(tmp);
			SetPlayerSkillLevel(gid, skill, tmp[0]);
			return true;
		}
		if(cmdhash == /* name */ -1079464476 )
		{
			new tmp[64], gid;
			CMD_TOKEN(tmp /*[32]*/);
			if(isnull(tmp)) return SendPlayerUsageMsg(playerid, cmd, "[playerid] [name]");
			gid = strid(tmp);
			if(!IsPlayerConnected(gid)) return SendClientMessage(playerid, COLOR_ERROR, "Incorrect ID!");
			CMD_TOKEN(tmp);
			//if(isnull(tmp)) return SendPlayerUsageMsg(playerid, cmd, "[playerid] [name]");
			return SetPlayerName(gid, tmp);
		}
		if(cmdhash == /* sethp */ 904728947 ||cmdhash == /* sethealth */ -20951603 ||cmdhash == /* setarmor */ 251239656 ||cmdhash == /* setarmour */ 164601491 )
		{
			new tmp[32], gid, Float:hp;
			CMD_TOKEN(tmp /*[32]*/);
			if(isnull(tmp)) return SendPlayerUsageMsg(playerid, cmd, "[playerid] [health] ([armour])");
			gid = strid(tmp);
			if(!IsPlayerConnected(gid))
				return SendClientMessage(playerid, COLOR_ERROR, "Incorrect ID!");
			CMD_TOKEN(tmp /*[32]*/);
			if(isnull(tmp)) return SendPlayerUsageMsg(playerid, cmd, "[playerid] [health] ([armour])");
			hp = floatstr(tmp);
			SetPlayerHealth(gid, hp);
			CMD_TOKEN(tmp /*[32]*/);
			if(!isnull(tmp))
			{
				hp = floatstr(tmp);
				SetPlayerArmour(gid, hp);
			}
			return true;
		}
		if(cmdhash == /* setvhp */ -1120435601  || cmdhash == /* setvehhp */ 1425275736 )
		{
			new tmp[32], gid, Float:hp, bool:isveh;
			CMD_TOKEN(tmp /*[32]*/);
			if(isnull(tmp)) return SendPlayerUsageMsg(playerid, cmd, "[playerid|vehicleid] [health]");
			gid = strid(tmp);
			if(!IsPlayerConnected(gid))
			{
				gid = strval(tmp);
				if(!IsVehicleConnected(gid))
					return SendClientMessage(playerid, COLOR_ERROR, "Incorrect vehicle ID!");
				else
					isveh = true;
			}
			else
				isveh = false;
			CMD_TOKEN(tmp /*[32]*/);
			if(isnull(tmp))
				return SendPlayerUsageMsg(playerid, cmd, isveh?("[vehicleid] [health]"):("[playerid] [health]"));
			hp = floatstr(tmp);
			if(!isveh)
				gid = GetPlayerVehicleID(gid);
			SetVehicleHealth(gid, hp);
			return true;
		}
		if(cmdhash == /* gravity */ 1696721381 )
		{
			new tmp[32],Float:gr;
			CMD_TOKEN(tmp /*[32]*/);
			if(isnull(tmp)) return SendPlayerUsageMsg(playerid, cmd, "[amount]");
			gr = floatstr(tmp);
			SetGravity(gr);
			//return true;
			return false; // to be continued...
		}
		if(cmdhash == /* fstyle */ 1308989848 )
		{
			new tmp[32];
			CMD_TOKEN(tmp /*[32]*/);
			if(isnull(tmp)) return SendPlayerUsageMsg(playerid, cmd, "[fightingstyle]");
			SetPlayerFightingStyle(playerid, strval(tmp));
			return true;
		}
		if(cmdhash == /* setworld */ -899274663 )
		{
			new tmp[32], gid;
			CMD_TOKEN(tmp /*[32]*/);
			if(isnull(tmp)) return SendPlayerUsageMsg(playerid, cmd, "[playerid] [worldid]");
			gid = strid(tmp);
			if(!IsPlayerConnected(gid))
				return SendClientMessage(playerid, COLOR_ERROR, "Incorrect ID!");
			CMD_TOKEN(tmp /*[32]*/);
			if(isnull(tmp)) return SendPlayerUsageMsg(playerid, cmd, "[playerid] [worldid]");
			tmp[0] = strval(tmp);
			SetPlayerVirtualWorld(gid, tmp[0]);
			format(tmp, sizeof(tmp), "World: %d", GetPlayerVirtualWorld(gid));
			SendClientMessage(playerid, COLOR_INFO1, tmp);
			return true;
		}
		if(cmdhash == /* desync */ 793714877 )
		{
			new tmp[32], gid;
			CMD_TOKEN(tmp /*[32]*/);
			if(isnull(tmp)) return SendPlayerUsageMsg(playerid, cmd, "[playerid] [worldid]");
			gid = strid(tmp);
			if(!IsPlayerConnected(gid))
				return SendClientMessage(playerid, COLOR_ERROR, "Incorrect ID!");
			issynced[gid] = !issynced[gid];
			format(tmp, sizeof(tmp), "%s(%d) sync: %s", GetPName(gid), gid, issynced[gid]?("on"):("off"));
			SendClientMessage(playerid, COLOR_INFO1, tmp);
			return true;
		}
	}
	if(cmdhash == /* atest */ 993048992 )
	{
		new atest, tmp[64];
		atest = IsPlayerAdminEx(playerid);
		if(atest == -1&&!isadm) SendClientMessage(playerid, COLOR_INFO1, "You are not an admin or system error!");
		format(tmp, sizeof(tmp), "Admin ID: %2d.", atest);
		SendClientMessage(playerid, COLOR_INFO2, tmp);
		if(!IsPlayerLogged(playerid))
			SendClientMessage(playerid, COLOR_INFO3, "You are not logged in!");
		if(!isadm)
			SendClientMessage(playerid, COLOR_INFO1, "Error: You cant use admin commands! You can log in using /login or register system error.");
		return true;
	}
	if(cmdhash == /* cobj */ 926798399 )
	{
		for(new i = 1; i<256; i++)
		{
			if(IsValidPlayerObject(playerid, i)) DestroyPlayerObject(playerid, i);
			if(isadm) if(IsValidObject(i)) DestroyObject(i);
		}
		//return true;
		return false; // to be continued...
	}
	if(cmdhash == /* eject */ 1882551230 )
	{
		new Float:ppos[3];
		if(isadm)
		{
			new tmp[32];
			CMD_TOKEN(tmp /*[32]*/);
			if(isnull(tmp)) return SendPlayerUsageMsg(playerid, cmd, "[playerid]");
			playerid = strid(tmp);
			if(!IsPlayerConnected(playerid)) return SendClientMessage(playerid, COLOR_ERROR, "Incorrect ID!");
		}
		GetPlayerPos(playerid, ppos[0], ppos[1], ppos[2]);
		SetPlayerPos(playerid, ppos[0], ppos[1], ppos[2]+3.5);
		return true;
	}
	if(cmdhash == /* remcur */ 1222538187 )
	{
		DestroyVehicle(GetPlayerVehicleID(playerid));
		return true;
	}
	if(cmdhash == /* cclear */ 1211167187 ||cmdhash == /* clearchat */ -1996337204 ||cmdhash == /* chatclear */ 1667601856 )
	{
		for(new i=0; i<=100; i++)
			if(isadm) SendClientMessageToAll(0xFFFFFFFF, "\n");
			else SendClientMessage(playerid, 0xFFFFFFFF, "\n");
		return true;
	}
	if(cmdhash == /* getinfo */ -1856085253 )
	{
		#define COLOR_INFO2EX (COLOR_INFO2-0x2F2F2F00)
		new tmp[128], gid, vid, Float:hp, Float:ap;
		new level;
		CMD_TOKEN(tmp);
		if(isnull(tmp))
			return SendPlayerUsageMsg(playerid, cmd, "[playerid] ([level])");
		// print hr break
		SendClientMessage(playerid, COLOR_YELLOW, "-------------------------------------------");
		gid = strid(tmp);
		// level
		CMD_TOKEN(tmp);
		if(isnull(tmp))
			level = 5;
		else
			level = strval(tmp);

		if(!IsPlayerConnected(gid)) return SendClientMessage(playerid, COLOR_ERROR, "Incorrect ID!");
		if(level >= 1)
		{
			GetPlayerHealth(gid, hp);
			GetPlayerArmour(gid, ap);
			format(tmp, sizeof(tmp), "Health: %0.2f; Armour: %0.2f; Money: %d; Score: %d; Skin: %d; Interior: %d; Ping: %d", hp, ap,
				GetPlayerMoney(gid), GetPlayerScore(gid), GetPlayerSkin(gid), GetPlayerInterior(gid), GetPlayerPing(gid));
			SendClientMessage(playerid, COLOR_INFO2, tmp);
		}
		if(level >= 2 && (vid = GetPlayerVehicleID(gid)) != 0) // car info
		{
			GetVehicleHealth(vid, hp);
			format(tmp, sizeof(tmp), "Vehicleid: %d; Modelid: %d; Health: %0.3f", vid, GetVehicleModel(vid), hp);
			SendClientMessage(playerid, COLOR_INFO2EX, tmp);
			if(level >= 3)
			{
				GetVehicleDamageStatus(vid, tmp[0], tmp[1], tmp[2], tmp[3]);
				format(tmp, sizeof(tmp), "Damage state: panels: %d, doors: %d, lights: %d, tires: %d",
					tmp[0], tmp[1], tmp[2], tmp[3]);
				SendClientMessage(playerid, COLOR_INFO2, tmp);
				format(tmp, sizeof(tmp), "Car Upgrades: ");
				for(new i=0, tmp2; i<14; i++)
				{
					tmp2 = GetVehicleComponentInSlot(vid, i);
					if(tmp2) format(tmp, sizeof(tmp), "%s %4d", tmp, tmp2);
					//printf("in loop: tmp = %s, tmp2 = %d", tmp, tmp2);
				}
				if(strlen(tmp) > 15)
					SendClientMessage(playerid, COLOR_INFO2EX, tmp);
			}
		}
		// debug info
		if(level >= 4)
		{
			new Float:ex[6];
			GetPlayerTime(gid, tmp[0], tmp[1]);
			GetPlayerKeys(gid, tmp[2], tmp[3], tmp[4]);
			tmp[5] = GetPlayerWeapon(gid);
			format(tmp, sizeof(tmp), "Time: %02d:%02d; Keys/UD/LR: %d/%d/%d; FS: %d; WL: %d; AW: %s(%d); ST1: %d; ST2: %d; DL: %d; VW: %d",
				tmp[0], tmp[1], tmp[2], tmp[3], tmp[4], GetPlayerFightingStyle(gid), GetPlayerWantedLevel(gid),
				GetWeaponNameEx(tmp[5]), tmp[5], GetPlayerState(gid), GetPlayerSpecialAction(gid), GetPlayerDrunkLevel(gid),
				GetPlayerVirtualWorld(gid));
			SendClientMessage(playerid, COLOR_INFO2EX, tmp);
			if(vid)
			{
				GetVehicleVelocity(vid, hp, ap, ex[0]);
				GetVehiclePos(vid, ex[1], ex[2], ex[3]);
				GetPlayerFacingAngle(gid, ex[4]);
				GetVehicleZAngle(vid, ex[5]);
				format(tmp, sizeof(tmp), "IC: Velocity: X: %0.3f Y: %0.3f Z: %0.3f; Position: X: %0.3f Y: %0.3f Z: %0.3f AIC: %0.3f AOF: %0.3f",
					hp, ap, ex[0], ex[1], ex[2], ex[3], ex[5], ex[4]);
				SendClientMessage(playerid, COLOR_INFO2EX, tmp);
			}
			else
			{
				GetPlayerVelocity(gid, hp, ap, ex[0]);
				GetPlayerPos(gid, ex[1], ex[2], ex[3]);
				GetPlayerFacingAngle(gid, ex[4]);
				format(tmp, sizeof(tmp), "OF: Velocity: X: %0.3f Y: %0.3f Z: %0.3f; Position: X: %0.3f Y: %0.3f Z: %0.3f A: %0.3f",
					hp, ap, ex[0], ex[1], ex[2], ex[3], ex[4]);
				SendClientMessage(playerid, COLOR_INFO2, tmp);
			}
		}
		// weapon bag
		if(level >= 2) for(new i=0; i<=12; i++)
		{
			GetPlayerWeaponData(gid, i, tmp[0], tmp[1]);
			//GetPlayerWeaponData(gid, i+1, tmp[2], tmp[3]);
			//GetPlayerWeaponData(gid, i+2, tmp[4], tmp[5]);
			if(!tmp[0]) continue;
			format(tmp, sizeof(tmp), "Slot %d: %s(%d); ammo: %d", //; Slot %2d: %20s(%2d), ammo: %4d",
				i, GetWeaponNameEx(tmp[0]), tmp[0], tmp[1]);//, i+1, tmp[2]?GetWeaponNameEx(tmp[2]):("none"), tmp[2], tmp[3]);
			SendClientMessage(playerid, (i&1)?COLOR_INFO2:COLOR_INFO2EX, tmp);
		}
		// pvars
		if(level >= 5 && isadm)
		{
			new varname[64];
			for(new i = 0, k = GetPVarsUpperIndex(gid); i < k; i++)
			{
				GetPVarNameAtIndex(gid, i, varname, sizeof(varname));
				FormatPVar(tmp, gid, varname);
				SendClientMessage(playerid, (i&1)?COLOR_INFO2:COLOR_INFO2EX, tmp);
			}
		}
		return false; // to be continued...
	}

	#undef CMD_TOKEN
	return false;
}



static FormatPVar(dest[], playerid, varname[], len = sizeof dest)
{
	switch(GetPVarType(playerid, varname))
	{
		case PLAYER_VARTYPE_INT:
			format(dest, len, "%s = %d", varname, GetPVarInt(playerid, varname));
		case PLAYER_VARTYPE_STRING:
		{
			GetPVarString(playerid, varname, dest, len);
			format(dest, len, "%s = \"%s\"", varname, dest);
		}
		case PLAYER_VARTYPE_FLOAT:
			format(dest, len, "%s = %f", varname, GetPVarFloat(playerid, varname));
		default: return false;
	}
	return true;
}


